<%--
  Created by IntelliJ IDEA.
  User: 康娜的小肥腿
  Date: 2020/3/25 0025
  Time: 15:41
--%>

<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">

<head>
    <base href="${pageContext.request.contextPath}/">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>学生管理系统</title>
    <link rel="stylesheet" href="css/heightlength.css">
    <link rel="stylesheet" href="css/mxjs.css">
    <link href="inspinia/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <script src="js/jquery.min.js"></script>
    <script src="js/mking.js"></script>
    <script src="bootstrap-3.3.7/js/bootstrap.min.js"></script>




</head>

<body>

<%--<jsp:include page="main.jsp">--%>
<%--<jsp:param name="menuItem" value="1"/>--%>
<%--</jsp:include>--%>
<div class="container">
    <div class="jsbg">
        <div id="chaxunkuang" class="col-lg-12 mxlength">
            <h2>查询</h2>
            <div class="tiaojian">
                <div class="panel-body">
                    <form class="form-inline" role="form" action="query/employee" method="post">
                        <div class="row">
                            <div class="col-md-12 column">
                                <div class="form-group col-md-2 column"></div>
                                <div class="form-group col-md-3 column">
                                    <label for="enameInput">姓名</label>
                                    <input type="text" name="ename" value="" class="form-control" id="enameInput"
                                           placeholder="请输入姓名">
                                </div>
                                <div class="form-group col-md-3 column">
                                    <label for="snoInput">学号</label>
                                    <input type="text" name="sno" value="" class="form-control" id="snoInput"
                                           placeholder="请输入学号" value="">
                                </div>
                                <div class="form-group col-md-3 column">
                                    <label for="zyInput">专业</label>
                                    <input type="text" name="zy" value="" class="form-control" id="zyInput"
                                           placeholder="请输入专业" value="">
                                </div>
                            </div>
                        </div>
                        <br/>

                        <div class="row">
                            <div class="col-md-8 column col-md-offset-2	  text-center">
                                <button type="submit" class="btn btn-primary" style="width: 100px;">查询</button>
                                <button type="reset" class="btn btn-default" style="width: 100px;margin-left: 10px;">
                                    重置
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <h2>学生信息</h2>
            <div class="xianshi">
                <div class="panel-body">
                    <table class="table table-striped table-hover text-center" id="xsxx" style="color:black;">
                        <tr class="text-center">
                            <th>姓名</th>
                            <th>学号</th>
                            <th>性别</th>
                            <th>民族</th>
                            <th>出生日期</th>
                            <th>联系方式</th>
                            <th>专业</th>
                            <th>操作</th>
                        </tr>
                        <c:forEach var="employee" items="${employeeList}">
                            <tr id="tr${employee.empno}" bgcolor="white">
<%--                                <td>${employee.empno}</td>--%>
                                <td>${employee.ename}</td>
                                <td>${employee.sno}</td>
                                <td>${employee.sex}</td>
                                <td>${employee.sal}族</td>
                                <td>${employee.hiredate}</td>
                                <td>${employee.phone}</td>
                                <td>${employee.zy}</td>
                                <td>
                                    <button type="button" onclick="toUpdate(${employee.empno})" class="btn btn-primary btn-sm"
                                            data-toggle="modal" data-target="#myUpdateModal" data-backdrop="static">
                                        <span class="">修改</span>
                                    </button>
                                    <button class="btn btn-danger btn-sm btn-delete"
                                            onclick="deleteEmployee(${employee.empno})">
                                        <span class="">删除</span>
                                    </button>
                                </td>
                            </tr>

                        </c:forEach>

                    </table>
                </div>
            </div>

        </div>
    </div>
</div>
<!-- 更新模态框 -->
<div id="myUpdateModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content" id="updateFormContent">

        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!-- Custom and plugin javascript -->
<script src="inspinia/js/inspinia.js"></script>
<!-- Sweet alert -->
<script src="inspinia/js/plugins/sweetalert/sweetalert.min.js"></script>

<script>
    function toUpdate(no) {
        $.get('updateForm.jsp?empno=' + no, function (res) {
            console.log(res);
            $('#updateFormContent').html(res);
        }, 'html');
    }

    // 更新
    function updateEmployee() {
// 获取表单中所有输入元素的数据
        var data = $('#updateForm').serialize();
        console.log(data);
        $.post('doUpdateForm.jsp', data, function (res) {
            console.log('更新状态：' + res.resultCode);
            if (res.resultCode === 1) {
//手动关闭模态框
                $('#myUpdateModal').modal('hide');
                $('#updateFormContent').empty();
//swal("Update!", "Your imaginary file has been updated.", "success");
                swal({
                    title: "修改结果",
                    text: "修改学生信息成功。",
                    type: "success",

                }, function () {
                    location.reload();
                });
            }
        }, 'json');
    }

    // 删除
    function deleteEmployee(empno) {
        $('.btn-delete').click(function () {
            swal({
                title: "删除确认",
                text: "您确定要删除该学生吗？",
                type: "warning",
                cancelButtonColor:"#229ADD",
                cancelButtonText:"取消",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: false
            }, function () {
// 发ajax请求
                $.get('doDelete.jsp?empno=' + empno, function (res) {
                    if (res.resultCode) {
                        swal("删除成功！", "记录已被安全删除。", "success");
                        $('#tr' + empno).remove();
                    } else {
                        swal("删除失败！", "删除记录失败，请重新操作。", "error");
                    }
                }, 'json');

            });
        });
    }
</script>

</body>

</html>
